package com.test3;

import java.util.Comparator;
import java.util.TreeMap;

/**
 * TreeMap的使用
 * 存储结构：红黑树
 */
public class TreeMapTest {
    public static void main(String[] args) {
        TreeMap<Students,String> treeMap = new TreeMap<>(new Comparator<Students>() {
            @Override
            public int compare(Students o1, Students o2) {
                return 0;
            }
        });
        //添加元素
        Students s1 = new Students("叶凡",100);
        Students s2 = new Students("姬皓月",90);
        Students s3 = new Students("黑皇",80);
        treeMap.put(s1,"地球");
        treeMap.put(s2,"北斗");
        treeMap.put(s3,"紫薇");
        System.out.println(treeMap);

        //删除
        treeMap.remove(new Students("黑皇",80));//这里只比较对象中的年龄，所以只要年龄一致，就能删除
        System.out.println(treeMap);//{Students{name='姬皓月', age=90}=北斗, Students{name='叶凡', age=100}=地球}
    }
}
